package top.drinyeit.weilong.activity;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.scu.miomin.shswiperefresh.core.SHSwipeRefreshLayout;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import top.drinyeit.weilong.R;
import top.drinyeit.weilong.app.Constant;
import top.drinyeit.weilong.base.BaseActivity;
import top.drinyeit.weilong.presenter.WithdrawDetailPresenter;
import top.drinyeit.weilong.util.SPUtil;

/**
 * Created by wu on 2018/1/24.
 */

public class WithdrawDetailActivity extends BaseActivity {
    public SHSwipeRefreshLayout shSwipeRefreshLayout;
    public RecyclerView recyclerView;
    private WithdrawDetailPresenter withdrawDetailPresenter;
    public int pageIndex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyclerview);

        initView();
        initData();

        setTitle(true,"提现明细");
    }


    private void initView() {
        shSwipeRefreshLayout = findViewById(R.id.mShswipeRefreshLayout);
        recyclerView = findViewById(R.id.mRecyclerView);

        initList();
    }

    private void initData(){
        withdrawDetailPresenter = new WithdrawDetailPresenter(this);
        Map<String,Object> map = new HashMap<>();
        map.put("action","user_encashment_detail");
        map.put("user_id", SPUtil.getShareString(Constant.USER_ID));
        map.put("pageIndex",1);
        withdrawDetailPresenter.getWithdrawDetail(map);
    }

    private void initList() {
        shSwipeRefreshLayout.setOnRefreshListener(new SHSwipeRefreshLayout.SHSOnRefreshListener() {
            @Override
            public void onRefresh() {
                Map<String,Object> map = new HashMap<>();
                map.put("action","user_encashment_detail");
                map.put("user_id", SPUtil.getShareString(Constant.USER_ID));
                map.put("pageIndex",1);
                withdrawDetailPresenter.getWithdrawDetail(map);
            }

            @Override
            public void onLoading() {
                Map<String,Object> map = new HashMap<>();
                map.put("action","user_encashment_detail");
                map.put("user_id", SPUtil.getShareString(Constant.USER_ID));
                map.put("pageIndex",pageIndex + 1);
                withdrawDetailPresenter.getWithdrawDetail(map);
            }

            @Override
            public void onRefreshPulStateChange(float v, int i) {

            }

            @Override
            public void onLoadmorePullStateChange(float v, int i) {

            }
        });
    }
}
